package com.may.wind.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 日志处理工具类
 */
public class ExceptionUtil {
    private final static Logger logger = LoggerFactory.getLogger(ExceptionUtil.class);

    /**
     * 打印异常信息
     */
    public static String getMessage(Exception exception) {
        String writeString = null;
        try (
                StringWriter stringWriter = new StringWriter();
                PrintWriter printWriter = new PrintWriter(stringWriter)) {
            exception.printStackTrace(printWriter);
            stringWriter.flush();
            stringWriter.flush();
            writeString = stringWriter.toString();
        } catch (IOException ioException) {
            ioException.printStackTrace();
            logger.error(ioException.getMessage());
        }
        return writeString;
    }
}
